#import "YQPPresentDetailModel.h"

#import "MYSheardPaymentParticularsVC.h"

#import "YQPInsureValidate.h"

@interface MYSheardPaymentParticularsVC ()
@property (nonatomic, strong) UIView * leftLineView;
@end

@implementation MYSheardPaymentParticularsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isNavShadow = YES;
    self.navigationItem.title = kYQLS(@"奖励金明细");
}

-(void)setupView {
    [super setupView];
    self.listTableView.backgroundColor = HexColor(0xFAFAFA);
    UIView *lineView = [UIView new];
    lineView.backgroundColor = kAPPThemeColor;
    self.leftLineView = lineView;
    
    [self.listTableView addSubview:lineView];
    
    lineView.frame = CGRectMake(20, 21, 1, 2000);
    kYQREGISTERTABLEVIEWCNIBHeaderFooter(@"MYCreditsExchangeRecordHeader");
    kYQREGISTERTABLEVIEWNIBCELL(@"MYCreditsExchangeCell");
    [self onStartRefresh];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self getPresentDetailList];
}

-(void)onStartRefresh {
    self.page = 1;
    [self getPresentDetailList];
}

- (void)onStartLoadMore {
    self.page ++ ;
    [self getPresentDetailList];
}

#pragma mark - 查询奖励金明细接口
-(void)getPresentDetailList {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"limit"] = @"10";
    parameters[@"page"] = @(self.page);
    
    YQSHOWLOADINGINVIEW
    [YQPNetWorkingManager sendPostRequest:kPOST_SHARE_DETAIL_URL parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        YQHIDELOADINGTIPS
        [self stopRefresh];
        if (responseObject.code == 0) {
            if (self.page == 1) {
                [self.dataArr removeAllObjects];
            }
            NSArray *arr = [YQPPresentModel mj_objectArrayWithKeyValuesArray:responseObject.data[@"list"]];
            [self.dataArr addObjectsFromArray:arr];
            [self.listTableView reloadData];
            
            if (arr.count < 10) {
                [self.listTableView.mj_footer endRefreshingWithNoMoreData];
            }
            
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
        
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
        [self stopRefresh];
    }];
    
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    YQPPresentModel *model = self.dataArr[indexPath.row];
    MYCreditsExchangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYCreditsExchangeCell"];
    
    cell.titleLb.text = NSStringFormat(@"%@ HKD%@",kYQLS(@"通过分享获得奖励金"),model.awardAmount);

    NSString *time = [YQPInsureValidate compareCurrentTime:[YQPInsureValidate timeInStr:model.createTime]];
    cell.timeLb.text = time;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 30;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    MYCreditsExchangeRecordHeader *header= [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"MYCreditsExchangeRecordHeader"];
    header.titleLb.text = kYQLS(@"今天");
    return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 41;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.leftLineView.frame = CGRectMake(20, 21, 1, scrollView.contentSize.height+kYQPScreenHeight);
    
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end
@end
